

; Sprite Class
; dies when the animation has looped once


(load "physics-object.scm")
(load "graphics-object.scm")
(load "vector.scm")

(define sprite%
  (class physics-object%
    
    ; PHYSICS-OBJECT%
    (inherit-field position)
    ; PUBLIC VARIABLES
    (init-field [sprite-name #f]
                [frame-time #i1/30])
    ; PRIVATE VARIABLES
    (define graphics-sprite (new graphics-object% [graphics-name sprite-name] [frame-time frame-time]))
    (define ended #f)
    
    (delegate get-width  graphics-sprite)
    (delegate get-height graphics-sprite)
    
    ; QUERIES
    (define/public (ended?)
      ended)
    
    ; Draw
    (define/override (draw dc)
      (send graphics-sprite draw dc (get-x position) (get-y position)))
    
    ; Update
    (define/override (update)
      (when (eq? 'restart (send graphics-sprite anim-advance))
        (set! ended #t))
      (not ended))
    
    ; Constructor/Initialization
    (super-new [size (make-size graphics-sprite)] [solid #f] [affected-by-gravity #f] [interactive #f])))

